import React from "react";
import GoodNode from "../../../Component/Good";
import MessageUtil from "../../../utils/MessageUtil";
import ShopServer from "../../../Server/Trade/ShopServer";
import UserCheck from "../../../utils/UserCheck";
import URL from "../../../Server/URL";
import Common from "../../../utils/Common";
// import './index.css';

export default class extends React.Component{
    
    constructor(props){
        super();

        MessageUtil.ShowSuspention("");

        let goods=[];
        this.state={
            goods
        }

        ShopServer.ShopShopManagement(UserCheck.GetUserID(),1)
        .then(response=>{
            console.log(response)
            response.data.forEach(i => {
                let timeStr="";
                
                let name="";
                let desc="";
                let price="";

                let stateInfo="";
                let color="";
                let colorRaw="";

                let insuranceStatus=false;// 有无飞行器保险
                let cashDepositStatus=false;//  保证金金额
                let img="";
                //1配件或者其他
                //0二手无人机
                //2租赁飞行器
                //3租赁配件或者其他
                let stateValue=0;
                if(i.SecondHandAccessories!==undefined){
                    Common.GetTimeStr(i.SecondHandAccessories.time);
                    colorRaw=i.SecondHandAccessories.status;
                    name=i.SecondHandAccessories.title;
                    desc="";
                    stateValue=i.SecondHandAccessories.status;
                    price=i.SecondHandAccessories.price;

                    img=URL.GetURL(i.SecondHandAccessories.imgUrl);
                    if(i.SecondHandAccessories.cashDeposit>0){
                        cashDepositStatus=true;
                    }
                }
                
                if(i.SecondHandAircraft!==undefined){
                    Common.GetTimeStr(i.SecondHandAircraft.time);
                    colorRaw=i.SecondHandAircraft.shopStatus;
                    desc="品牌: "+i.SecondHandAircraft.aerocraftBrand;
                    name=i.SecondHandAircraft.title;
                    stateValue=i.SecondHandAircraft.status;
                    price=i.SecondHandAircraft.price;

                    img=URL.GetURL(i.SecondHandAircraft.aerocraftImgUrl) ;
                    if(i.SecondHandAircraft.cashDeposit>0){
                        cashDepositStatus=true;
                    }

                    if(i.SecondHandAircraft.insuranceStatus){
                        insuranceStatus=i.SecondHandAircraft.insuranceStatus===0;
                    }
                }
                
                switch(colorRaw){
                    case "0":
                        color="red";
                        // color="#5393EB";//blue
                        break;
                    case "1":
                        color="#61BC12";
                        break;
                    case "2":
                        color="#61BC12";//green
                        break;
                    default:
                        break;

                }
                let state=[ "接单中","已接单","已完成","已取消"]

                stateInfo=<span>派单状态: <font color={color}>{state[stateValue]}</font></span>;

                


                goods.push(
                    <GoodNode header={ URL.GetURL(i.userHead)}
                    key={i}
                    order={false}
                    insurance={insuranceStatus}
                    guaranteeMoney={cashDepositStatus}
                    modify={false} 
                    heart={false} 
                    bag={false} delete={false} 
                    name={name}
                    time={timeStr}
                    desc={`${desc}`}
                    state={stateInfo}
                    price={price}
                    img={img}
                    />
                )
            });


            console.log(response)

            this.setState({
                goods
            },()=>{
                MessageUtil.ChangeHeight();
            })
        });
    }
    render(){
        return(
            <div>
                <div className="">
                    {this.state.goods}
                </div>
            </div>
            
        )
    }
}